# compile
Cargo-MSVC -Arch86 -Release

# init
dotnet tool restore
Install-Module -Name PSToml -Scope CurrentUser
scoop install nuget

# get nuget info
$id = 'WmicReplacementCli'
$GitVersion = dotnet gitversion  /output json | ConvertFrom-Json
$version = $GitVersion.NuGetVersionV2
$crate = Get-Content .\wmic_app\Cargo.toml | ConvertFrom-Toml
$authors = ($crate.package.authors -replace '<', '&lt;' ) -replace '>', '&gt;'
$copyright = $crate.package.metadata.winres.LegalCopyright
$description = $crate.package.description
$nuspec = @"
<?xml version="1.0" encoding="utf-8"?>
<package >
    <metadata>
    <id>$id</id>
    <version>$version</version>
    <authors>$authors</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <projectUrl>https://gitee.com/zcstudio/wmic-rs</projectUrl>
    <description>$description</description>
    <releaseNotes></releaseNotes>
    <copyright>$copyright</copyright>
    <tags>wmic</tags>
    <contentFiles>
            <files include="any/any/bin/wmic.exe" buildAction="None" copyToOutput="true"/>
        </contentFiles>
    </metadata>
</package>
"@

# pack
Remove-Item publish\* -Recurse -Force
mkdir publish\temp -Force
Set-Content -Path "publish\temp\$id.nuspec" -Value $nuspec
mkdir publish\temp\contentFiles\any\any\bin -Force
Copy-Item .\target\i686-pc-windows-msvc\release\wmic.exe publish\temp\contentFiles\any\any\bin -Force

Push-Location .\publish\temp
nuget pack ".\$id.nuspec"
Pop-Location

Copy-Item "publish\temp\$($id).$($version).nupkg" publish -Force
Remove-Item publish\temp -Force -Recurse